package com.fruit.audit.exception;

/**
 * <h4>异常说明</h4>
 * <ul>
 * <li>0000~0999:数据库异常</li>
 * <li>1000~1999:空指针异常</li>
 * <li>2000~2999:参数是否合法</li>
 * <li>3000~3999:参数验证</li>
 * <li>4000~4999:对接异常</li>
 * <li>7000~7999:io异常</li>
 * <li>8000~8999:系统异常</li>
 * <li>9000~9999:其他异常</li>
 * <ul>
 * 
 * 
 * @author 梁景皓###
 * 
 */
public enum FruitExceptionEnum {
	
	SQL_ERROR("0000", "数据库异常"),
	
	QUERY_ERROR("0100", "查询异常"),
	
	INSERT_ERROR("0200", "插入异常"),
	
	UPDATE_ERROR("0300", "更新异常"),
	
	PARAM_IS_NULL("1000", "参数{0}为空"),
	
	PARAM_ILLEGAL("2000", "参数{0}不合法"),
	
	XY_ILLEGAL("2001", "坐标x={0},y={1}不合法"),
	
	PARAN_EXCEPTION("3000", "参数验证"),
	
	USER_WRONG_EXCEPTION("3001", "用户不存在"),
	
	PASSWORD_WRONG_EXCEPTION("3002", "密码错误"),
	
	USER_DELETE_EXCEPTION("3003", "用户已经被管理员删除"),
	
	USER_EXIST_EXCEPTION("3004", "用户已经存在"),
	
	TOKEN_EXPIRE_EXCEPTION("3005", "token={0}已经过期"),
	
	ORDER_WRONG_EXCEPTION("3006", "教师teacherId={0}没有操作此订单orderId={0}的权限"),
	
	ORDER_GRABED_EXCEPRION("3007", "订单orderId={0}已经被抢走啦!"),
	
	ORDER_EXPIRE_EXCEPRION("3008", "订单orderId={0}已经过期啦!"),
	
	USER_ROLE_WRONG_EXCEPTION("3004", "用户角色不正确"),
	
	CONNECT_ERROR("4000", "对接异常"),
	
	PUSH_MESSAGE_ERROR("4001", "消息推送异常"),
	
	OTHER_ERROR("9000", "其他异常") ;
	
	private String code;
	private String message;

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	private FruitExceptionEnum(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public static String getMessage(String code) {
		for (FruitExceptionEnum exp : values()) {
			if (exp.getCode().equals(code)) {
				return exp.getMessage();
			}
		}
		return null;
	}

	public String getMessage(String[] args) {
		String message = this.message;
		for(int i=0; i<args.length; i++) {
			message = message.replace("{" + i + "}", args[i]);
		}
		return message;
	}
}